\hypertarget{class_com_port}{\section{Com\+Port类 参考}
\label{class_com_port}\index{Com\+Port@{Com\+Port}}
}


串口设备类.  




{\ttfamily \#include $<$Com\+Port.\+h$>$}

类 Com\+Port 继承关系图\+:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[height=2.000000cm]{class_com_port}
\end{center}
\end{figure}
\subsection*{Public 成员函数}
\begin{DoxyCompactItemize}
\item 
\hyperlink{class_com_port_a18f814468b55405add84e4f8271a95e9}{Com\+Port} ()
\begin{DoxyCompactList}\small\item\em 构造函数 \end{DoxyCompactList}\item 
virtual \hyperlink{class_com_port_a60f4557b68a559975a0404f77480e038}{$\sim$\+Com\+Port} ()
\begin{DoxyCompactList}\small\item\em 析构函数 \end{DoxyCompactList}\item 
virtual sint32 \hyperlink{class_com_port_aae244aab39a2a0321016bc21c5164e24}{open} (const char $\ast$dev\+Name, sint32 io\+Mode)
\begin{DoxyCompactList}\small\item\em 打开串口 \end{DoxyCompactList}\item 
virtual sint32 \hyperlink{class_com_port_a75e33f87300daf62df4ae5bd21c0cbc4}{close} ()
\begin{DoxyCompactList}\small\item\em 关闭串口 \end{DoxyCompactList}\item 
virtual sint32 \hyperlink{class_com_port_a881598304b2cc737043030f99e930d8e}{read\+Data} (char $\ast$buf, sint32 len, sint32 timeout\+Ms=-\/1)
\begin{DoxyCompactList}\small\item\em 读串口数据 \end{DoxyCompactList}\item 
virtual sint32 \hyperlink{class_com_port_a6559f7c675d8e7ddd00a016da4d3c783}{write\+Data} (const char $\ast$buf, sint32 len, sint32 timeout\+Ms=-\/1)
\begin{DoxyCompactList}\small\item\em 写串口数据 \end{DoxyCompactList}\item 
virtual sint32 \hyperlink{class_com_port_ae6f5483e8166888e697265f1dfc3fddf}{set\+Attribute} (sint32 attr, sint32 value)
\begin{DoxyCompactList}\small\item\em 设置串口属性 \end{DoxyCompactList}\item 
virtual sint32 \hyperlink{class_com_port_aa470a678897eaa01b7ffd6d5f8519ac4}{get\+Attribute} (sint32 attr)
\begin{DoxyCompactList}\small\item\em 获取串口属性 \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{额外继承的成员函数}


\subsection{详细描述}
串口设备类. 

\subsection{构造及析构函数说明}
\hypertarget{class_com_port_a18f814468b55405add84e4f8271a95e9}{\index{Com\+Port@{Com\+Port}!Com\+Port@{Com\+Port}}
\index{Com\+Port@{Com\+Port}!Com\+Port@{Com\+Port}}
\subsubsection[{Com\+Port}]{\setlength{\rightskip}{0pt plus 5cm}Com\+Port\+::\+Com\+Port (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}\label{class_com_port_a18f814468b55405add84e4f8271a95e9}


构造函数 


\begin{DoxyParams}{参数}
{\em none} & \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
none 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
默认串口波特率为9600,8位数据位,1位停止位,无奇偶校验位,无流控 
\end{DoxyNote}
\hypertarget{class_com_port_a60f4557b68a559975a0404f77480e038}{\index{Com\+Port@{Com\+Port}!````~Com\+Port@{$\sim$\+Com\+Port}}
\index{````~Com\+Port@{$\sim$\+Com\+Port}!Com\+Port@{Com\+Port}}
\subsubsection[{$\sim$\+Com\+Port}]{\setlength{\rightskip}{0pt plus 5cm}Com\+Port\+::$\sim$\+Com\+Port (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_com_port_a60f4557b68a559975a0404f77480e038}


析构函数 


\begin{DoxyParams}{参数}
{\em none} & \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
none 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


\subsection{成员函数说明}
\hypertarget{class_com_port_a75e33f87300daf62df4ae5bd21c0cbc4}{\index{Com\+Port@{Com\+Port}!close@{close}}
\index{close@{close}!Com\+Port@{Com\+Port}}
\subsubsection[{close}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Com\+Port\+::close (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_com_port_a75e33f87300daf62df4ae5bd21c0cbc4}


关闭串口 


\begin{DoxyParams}{参数}
{\em none} & \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
成功返回\+S\+T\+A\+T\+U\+S\+\_\+\+O\+K,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


重载 \hyperlink{class_i_o_device_a1120c9e7a7c4d0b23083effbe4cb6279}{I\+O\+Device} .

\hypertarget{class_com_port_aa470a678897eaa01b7ffd6d5f8519ac4}{\index{Com\+Port@{Com\+Port}!get\+Attribute@{get\+Attribute}}
\index{get\+Attribute@{get\+Attribute}!Com\+Port@{Com\+Port}}
\subsubsection[{get\+Attribute}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Com\+Port\+::get\+Attribute (
\begin{DoxyParamCaption}
\item[{sint32}]{attr}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_com_port_aa470a678897eaa01b7ffd6d5f8519ac4}


获取串口属性 


\begin{DoxyParams}{参数}
{\em attr} & 属性类型\+C\+O\+M\+\_\+\+A\+T\+T\+R\+\_\+\+E \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
sint32 成功返回属性对应的值,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


实现了 \hyperlink{class_i_o_device}{I\+O\+Device}.

\hypertarget{class_com_port_aae244aab39a2a0321016bc21c5164e24}{\index{Com\+Port@{Com\+Port}!open@{open}}
\index{open@{open}!Com\+Port@{Com\+Port}}
\subsubsection[{open}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Com\+Port\+::open (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{dev\+Name, }
\item[{sint32}]{io\+Mode}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_com_port_aae244aab39a2a0321016bc21c5164e24}


打开串口 


\begin{DoxyParams}{参数}
{\em dev\+Name} & 设备名称,如/dev/tty\+S\+A\+C0 \\
\hline
{\em mode} & 设备属性,如\+I\+O\+\_\+\+M\+O\+D\+E\+\_\+\+R\+D\+\_\+\+O\+N\+L\+Y \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
sint32 成功返回\+S\+T\+A\+T\+U\+S\+\_\+\+O\+K,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
如果要修改串口属性,必须在open前进行设置 
\end{DoxyNote}


重载 \hyperlink{class_i_o_device_a426aac91300f077d57b1f30c76c7c430}{I\+O\+Device} .

\hypertarget{class_com_port_a881598304b2cc737043030f99e930d8e}{\index{Com\+Port@{Com\+Port}!read\+Data@{read\+Data}}
\index{read\+Data@{read\+Data}!Com\+Port@{Com\+Port}}
\subsubsection[{read\+Data}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Com\+Port\+::read\+Data (
\begin{DoxyParamCaption}
\item[{char $\ast$}]{buf, }
\item[{sint32}]{len, }
\item[{sint32}]{timeout\+Ms = {\ttfamily -\/1}}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_com_port_a881598304b2cc737043030f99e930d8e}


读串口数据 


\begin{DoxyParams}{参数}
{\em buf} & 存放读取的数据的缓存 \\
\hline
{\em len} & buf缓存的大小 \\
\hline
{\em timeout\+Ms} & 超时时间,-\/1\+:阻塞,0\+:立即返回,$>$0\+:超时时间ms \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
sint32 成功返回读取的数据长度,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


实现了 \hyperlink{class_i_o_device}{I\+O\+Device}.

\hypertarget{class_com_port_ae6f5483e8166888e697265f1dfc3fddf}{\index{Com\+Port@{Com\+Port}!set\+Attribute@{set\+Attribute}}
\index{set\+Attribute@{set\+Attribute}!Com\+Port@{Com\+Port}}
\subsubsection[{set\+Attribute}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Com\+Port\+::set\+Attribute (
\begin{DoxyParamCaption}
\item[{sint32}]{attr, }
\item[{sint32}]{value}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_com_port_ae6f5483e8166888e697265f1dfc3fddf}


设置串口属性 


\begin{DoxyParams}{参数}
{\em attr} & 属性类型\+C\+O\+M\+\_\+\+A\+T\+T\+R\+\_\+\+E \\
\hline
{\em value} & 属性对应的值 \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
sint32 成功返回\+S\+T\+A\+T\+U\+S\+\_\+\+O\+K,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


实现了 \hyperlink{class_i_o_device}{I\+O\+Device}.

\hypertarget{class_com_port_a6559f7c675d8e7ddd00a016da4d3c783}{\index{Com\+Port@{Com\+Port}!write\+Data@{write\+Data}}
\index{write\+Data@{write\+Data}!Com\+Port@{Com\+Port}}
\subsubsection[{write\+Data}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Com\+Port\+::write\+Data (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{buf, }
\item[{sint32}]{len, }
\item[{sint32}]{timeout\+Ms = {\ttfamily -\/1}}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_com_port_a6559f7c675d8e7ddd00a016da4d3c783}


写串口数据 


\begin{DoxyParams}{参数}
{\em data} & 要写入的数据 \\
\hline
{\em len} & 写入数据的长度 \\
\hline
{\em timeout\+Ms} & 超时时间,-\/1\+:阻塞,0\+:立即返回,$>$0\+:超时时间ms \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
sint32 成功返回写入的数据长度,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


实现了 \hyperlink{class_i_o_device}{I\+O\+Device}.



该类的文档由以下文件生成\+:\begin{DoxyCompactItemize}
\item 
libemb/inc/\hyperlink{_com_port_8h}{Com\+Port.\+h}\item 
libemb/src/Com\+Port.\+cpp\end{DoxyCompactItemize}
